package com.qijian.flowable.domain.query;

import com.baomidou.mybatisplus.annotation.TableName;
import com.qijian.common.utils.mybatis.WhereType;
import com.qijian.common.utils.mybatis.WhereTypeEnum;
import lombok.Data;
import lombok.ToString;

import java.util.Date;
import java.util.List;
import java.util.Set;


/**
 * 流程对象 查询条件类
 *
 * @author qijian
 * @date 2024-03-01
 */

@Data
@ToString
@TableName("main_flow")
public class FlowQuery {

    @WhereType(filed = "id")
    private Long id;
    @WhereType(filed = "id", type = WhereTypeEnum.IN)
    private Set<Long> ids;
    @WhereType(filed = "code", type = WhereTypeEnum.LIKE)
    private String code;
    @WhereType(filed = "flow_type")
    private String flowType;

    @WhereType(filed = "main_flow_type", type = WhereTypeEnum.LIKE)
    private String mainFlowType;

    @WhereType(filed = "approval_by")
    private String approvalBy;
    @WhereType(filed = "approval_time",type = WhereTypeEnum.BETWEEN)
    private Date[] approvalTime;
    @WhereType(filed = "submission_time",type = WhereTypeEnum.BETWEEN)
    private Date[] submissionTime;

    @WhereType(filed = "create_time",type = WhereTypeEnum.BETWEEN)
    private String[] createTime;

    @WhereType(filed = "remark")
    private String remark;

    @WhereType(filed = "remark", tableName = "main_flow_detail", type = WhereTypeEnum.LIKE)
    private String dataType;

    @WhereType(filed = "title", type = WhereTypeEnum.LIKE)
    private String title;
    @WhereType(filed = "action")
    private String action;
    @WhereType(filed = "create_by_id")
    private Long createById;
    @WhereType(filed = "dept_id")
    private Long deptId;
    @WhereType(filed = "dept_name")
    private String deptName;

    @WhereType(func = "EXISTS (select 1 from t_flowable_record f  where otd_record_ncr.id = f.source_id and f.business_key= 'otd_record_ncr' and f.user_id ={1})")
    private Long u;


    @WhereType(func = "EXISTS (select 1 from t_flowable_record f  where main_flow.id = f.source_id and f.business_key= '{1}' and f.user_id ={3})",func_field_value = {"2"})
    private String[] uArr;


    @WhereType(func = "EXISTS (select 1 from t_flowable_record f left join ACT_RU_TASK ru on ru.PROC_INST_ID_=f.process_instance_id inner join ACT_HI_IDENTITYLINK i on i.TASK_ID_=ru.ID_  where otd_record_ncr.id = f.source_id and f.business_key= 'otd_record_ncr'  and ( ru.ASSIGNEE_ ={1} or i.USER_ID_ = {1} ))")
    private Long i;

    @WhereType(func = "EXISTS (select 1 from t_flowable_record f left join ACT_RU_TASK ru on ru.PROC_INST_ID_=f.process_instance_id inner join ACT_HI_IDENTITYLINK i on i.TASK_ID_=ru.ID_  where main_flow.id = f.source_id and f.business_key= '{1}'  and ( ru.ASSIGNEE_ ={3} or i.USER_ID_ = {3} ))",func_field_value = {"2"})
    private String[] iArr;

    @WhereType(filed = "approval_status" ,type = WhereTypeEnum.IN)
    private List<String> approve;

    @WhereType(func = "(main_flow.code like concat('%', {1}, '%') or main_flow.title like concat('%', {1}, '%') or main_flow.create_by like concat('%', {1}, '%') or " +
            "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and json_valid(main_flow_detail.extra) and (json_extract(main_flow_detail.extra, '$.name') like  concat('%', {1}, '%') " +
            "or json_extract(main_flow_detail.extra, '$.code') like  concat('%', {1}, '%') " +
            "or json_extract(main_flow_detail.extra, '$.number') like  concat('%', {1}, '%') " +
            "or json_extract(main_flow_detail.extra, '$.eqpName') like  concat('%', {1}, '%') " +
            "or json_extract(main_flow_detail.extra, '$.type') like  concat('%', {1}, '%') " +
            "or json_extract(main_flow_detail.extra, '$.spec') like  concat('%', {1}, '%') " +
            "or json_extract(main_flow_detail.extra, '$.unit') like  concat('%', {1}, '%')" +
            ")))")
    private String condition;

    @WhereType(func = "("+
            "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and main_flow_detail.name like  concat('%', {1}, '%') " +
            "))")
    private String projectMachineNo1;


    @WhereType(func = "("+
            "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and ("+
            "main_flow_detail.spec like  concat('%', {1}, '%') " +
            "))")
    private String content;



    @WhereType(func = "("+
            "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and ("+
            "main_flow_detail.extra like  concat('%', {1}, '%') " +
            "))")
    private String contentType;

    /**
     * 发起人
     */
    @WhereType(func = "main_flow.create_by like concat('%', {1}, '%')")
    private String createBy;

    /**
     * 刀具名称
     */
    @WhereType(func = "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and json_valid(main_flow_detail.extra) and (json_extract(main_flow_detail.extra, '$.name') like  concat('%', {1}, '%') " +
            "))")
    private String name;

    /**
     * 激光码
     */
    @WhereType(func = "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and json_valid(main_flow_detail.extra) and (json_extract(main_flow_detail.extra, '$.code') like  concat('%', {1}, '%') " +
            "))")
    private String knifeCode;



    /**
     * 激光码
     */
    @WhereType(func = "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and json_valid(main_flow_detail.extra) and (json_extract(main_flow_detail.extra, '$.factoryArea') like  concat('%', {1}, '%') " +
            "))")
    private String factoryArea;


    /**
     * 刀具编码
     */
    @WhereType(func = "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and json_valid(main_flow_detail.extra) and (json_extract(main_flow_detail.extra, '$.number') like  concat('%', {1}, '%') " +
            "))")
    private String number;

    /**
     * 设备名称
     */
    @WhereType(func = "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and json_valid(main_flow_detail.extra) and (json_extract(main_flow_detail.extra, '$.eqpName') like  concat('%', {1}, '%') " +
            "))")
    private String eqpName;

    @WhereType(func = "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and json_valid(main_flow_detail.extra) and (json_extract(main_flow_detail.extra, '$.type') like  concat('%', {1}, '%') " +
            "))")
    private String type;

    /**
     * 规格
     */
    @WhereType(func = "main_flow_detail.id in (select main_flow_detail.id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and json_valid(main_flow_detail.extra) and (json_extract(main_flow_detail.extra, '$.spec') like  concat('%', {1}, '%') " +
            "))")
    private String spec;
    @WhereType(func = "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and json_valid(main_flow_detail.extra) and (json_extract(main_flow_detail.extra, '$.unit') like  concat('%', {1}, '%') " +
            "))")
    private String unit;

    /**
     * 开工令
     */
    @WhereType(func = "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and json_valid(main_flow_detail.extra) and (json_extract(main_flow_detail.extra, '$.projects') like  concat('%', {1}, '%') " +
            "))")
    private String projectMachineNo;

    @WhereType(func = "main_flow.id in (select main_flow_detail.main_id from main_flow_detail where  main_flow_detail.is_del = 0  " +
            "and json_valid(main_flow_detail.extra) and (json_extract(main_flow_detail.extra, '$.eqpNumber') like  concat('%', {1}, '%') " +
            "))")
    private String eqpNumber;

    @WhereType(deptTableName = "sys_user", userTableName = "sys_user")
    private Boolean dataScope;


    @WhereType(ignore= true)
    private List<String> approvalStatus;


    @WhereType(deptTableName = "apply_name", userTableName = "sys_user")
    private String applyName;


}
